package cn.songwang.org.service.impl;

import cn.songwang.basic.PageList;
import cn.songwang.org.domain.Department;
import cn.songwang.org.mapper.DepartmentMapper;
import cn.songwang.org.query.DepartmentQuery;
import cn.songwang.org.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements DepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;
    @Override
    @Transactional
    public void add(Department department) {
        departmentMapper.add(department);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        departmentMapper.delete(id);
    }

    @Override
    @Transactional
    public void update(Department department) {
        departmentMapper.update(department);
    }

    @Override
    public Department findByid(Long id) {
        return departmentMapper.findByid(id);
    }
    @Override
    public List<Department> finAll(DepartmentQuery query) {
        return departmentMapper.finAll(query);
    }

    @Override
    public Long count(DepartmentQuery query) {
        return departmentMapper.count(query);
    }

    @Override
    public PageList<Department> findQuery(DepartmentQuery query) {
        //高级查询后总条数
        Long count = departmentMapper.count(query);
        //高级查询后分页的当前页数据
        List<Department> rows = departmentMapper.findQuery(query);
        //把条数和数据封装到pageList对象中
        return new PageList<>(count,rows);
    }
}
